20230322
[shlib.git] / testing / 3.shlib_v0_1_testing.Testing for shlib v0_1.unit / 1.shlibinc_testing.shlibinc Testing.unit / scripts / uniq.shlib
blob065b218de132af0e09517d7158a64c708548f3f7
1 #!/bin/bash
2 ############################################################
3 # source: uniq.shlib
4 # author: devenkong(18151155@qq.com)
5 # date: 2021-10-03
6 ############################################################
7 # Copyright (C) 2022- Free Software Foundation, Inc.
8 # This configure script is free software; the Free Software
9 # Foundation gives unlimited permission to copy, distribute
10 # and modify it.
11 ############################################################
12 # note:
13 # this is a test shlib file for nest include testing. env
14 # var and function can work in nest include.
15 ############################################################
19 # todo£º
20 # @
23 dbgout ()
25 echo -ne "$@"
28 dbgout "load uniq.shlib at the beginning ...\n"
31 # this cmd enable alias feature in script. it is disabled in default.
32 shopt -s expand_aliases
35 # global variable re-init if this shlib has been loaded.
36 # and the code after 'uniqlib' will not be loaded repeatly.
37 # invoke PROG_GVAR_INIT before 'uniqlib'.
38 # if this shlib has not been loaded, uniqlib will not skip
39 # loading code after it.
41 echo -ne "PROG_GVAR_INIT uniq\n"
42 PROG_GVAR_INIT uniq.shlib
44 echo -ne "uniqlib uniq\n"
45 uniqlib uniq.shlib
47 echo -ne "normal init invoke.\n"
49 ##############################
50 # section: shlib include
51 ##############################
52 . shlibinc
54 #include stdio.shlib
57 ##############################
58 # section: public comment info
59 ##############################
62 ##############################
63 # section: variable define
64 ##############################
66 shlib_uniq_init ()
68 # global variable init.
69 if [[ ! -v TEST_UNIQ ]]; then
70 TEST_UNIQ=1
71 else
72 TEST_UNIQ=$(( TEST_UNIQ + 1 ))
75 # global exported variable init.
76 if [[ ! -v TEST_INC_CNT ]]; then
77 declare -g -x TEST_INC_CNT=1
78 else
79 TEST_INC_CNT=$(( TEST_INC_CNT + 1 ))
82 dbgout "shlib_uniq_init() is invoked in uniq.shlib!\n"
83 dbgout "TEST_UNIQ defined in uniq.shlib is '$TEST_UNIQ'.\n"
84 dbgout "TEST_INC_CNT defined in uniq.shlib is '$TEST_INC_CNT'.\n"
85 dbgout "TEST_INC_CNT is $TEST_INC_CNT, it is exported by parent process.\n"
88 # this func will be invoke in first inclussion.
89 shlib_uniq_init
92 # global variable init function invoking.
93 # invoke GVAR_INIT if it is running at first time.
95 #GVAR_INIT uniq
98 ##############################
99 # section: private function
100 ##############################
104 ##############################
105 # section: public function
106 ##############################
109 # fsyntax: uniq_test_func
110 # fdesc: this is a test func for uniq testing.
112 uniq_test_func ()
114 dbgout "uniq_test_func(TEST_UNIQ=$TEST_UNIQ, TEST_INC_CNT=$TEST_INC_CNT) is invoked in uniq.shlib.\n"
117 alias uniq_test_alias="dbgout \"uniq_test_alias() is an example in uniq.shlib.\n\""
120 dbgout "load uniq.shlib at the tail ...\n"
122 ######################
123 # section: file tail
124 ######################